
function changeModelColorLoading(self, tiyData) {
  tiyData.tStatus.modifyModal.isLoading = false;
  self.$nextTick(function () {
    tiyData.tStatus.modifyModal.isLoading = true;
  });
}

export const init = (self, tiyData) => {
  tiyData.tPage.currentPage = 1;
  tiyData.tPage.stepNumber = 40;
  tiyData.tParam.postageName = '';
  tiyData.tParam.searchParams.keyWord = '';
  tiyData.tStatus.modifyModal.isShow = false;
  tiyData.tStatus.decryptedModal.isShow = false;
}

export const webList = (self, tiyData) => {
  self.$Spin.show();
  self.$apiOther.queryEmployeeTerminalMarks({
    pageNum:tiyData.tPage.currentPage,
    pageSize:tiyData.tPage.stepNumber,
    keyWord:tiyData.tParam.searchParams.keyWord
  }).then(function (response) {
    self.$Spin.hide();
    if (response.success) {
      tiyData.tParam.length = [];
      tiyData.tData.employeeTerminalList.splice(0,tiyData.tData.employeeTerminalList.length) ;
      let markPage = response.result;
      tiyData.tPage.total = markPage.total;
      tiyData.tPage.stepNumber = markPage.pageSize;
      if (markPage.list.length !==0){
        markPage.list.forEach(
          function (item) {
            tiyData.tData.employeeTerminalList.push(item);
          }
        );
      }

    } else {
      self.$Spin.hide();
      self.$Message.error(response.errorMessage);
    }
  });
};

export const saveEmployeeTerminal = (self, tiyData) => {
    if (tiyData.tParam.employeeTerminal.employeeId == ""){
      self.$Message.error({content:"请选择员工"})
      return
    }
    if (tiyData.tParam.employeeTerminal.terminalId == ""){
      self.$Message.error({content:"请选择终端"})
      return
    }
    self.$Spin.show();
    tiyData.tStatus.modifyModal.isLoading = true;
    self.$apiOther.addEditEmployeeTerminalMark({
      id:tiyData.tParam.employeeTerminal.id,
      employeeId:tiyData.tParam.employeeTerminal.employeeId,
      terminalId:tiyData.tParam.employeeTerminal.terminalId,
      expireTime:tiyData.tParam.employeeTerminal.expireTime,
      effectiveTime:tiyData.tParam.employeeTerminal.effectiveTime,
    }).then(function (response) {
      self.$Spin.hide();
      changeModelColorLoading(self, tiyData);
      if (response.success) {
        tiyData.tStatus.modifyModal.isShow=false;
        webList(self, tiyData);
        self.$Message.success('提交成功!');
      } else {
        tiyData.tStatus.modifyModal.isLoading = false;
        self.$Message.error(response.errorMessage);
      }
    });
};

export const modifyEmployeeTerminal = (self, tiyData,index) => {
  let selectedEmployeeTerminal= tiyData.tData.employeeTerminalList[index];
  tiyData.tParam.employeeTerminal.id = selectedEmployeeTerminal.id;
  tiyData.tParam.employeeTerminal.employeeId = selectedEmployeeTerminal.employeeId;
  tiyData.tParam.employeeTerminal.employeeName = selectedEmployeeTerminal.employeeName;
  tiyData.tParam.employeeTerminal.terminalId = selectedEmployeeTerminal.terminalId;
  tiyData.tParam.employeeTerminal.terminalNo = selectedEmployeeTerminal.terminalNo;
  tiyData.tParam.employeeTerminal.effectiveTime = selectedEmployeeTerminal.effectiveTime;
  tiyData.tParam.employeeTerminal.expireTime = selectedEmployeeTerminal.expireTime;
  if (selectedEmployeeTerminal.effectiveTime == -1 && selectedEmployeeTerminal.expireTime == -1 ){
    tiyData.tParam.employeeTerminal.isLongTerm = true;
  }else {
    tiyData.tParam.employeeTerminal.isLongTerm = false;
  }
  tiyData.tParam.employeeTerminal.startEndTime.length = 0;
  if(selectedEmployeeTerminal.effectiveTime > 0){
    tiyData.tParam.employeeTerminal.startEndTime.push(new Date(parseInt(selectedEmployeeTerminal.effectiveTime + (new Date().getTimezoneOffset() * 1000 * 60))) );//转换为UTC时间显示
    tiyData.tParam.employeeTerminal.startEndTime.push(new Date(parseInt(selectedEmployeeTerminal.expireTime + (new Date().getTimezoneOffset() * 1000 * 60))));
  }
  self.choosedEmployee = {id:selectedEmployeeTerminal.employeeId, name:selectedEmployeeTerminal.employeeName};
  self.choosedTerminal = {id:selectedEmployeeTerminal.terminalId, name:selectedEmployeeTerminal.terminalNo};
  tiyData.tStatus.modifyModal.isShow=true
  tiyData.tStatus.modifyModal.title="修改电脑标记";
};


export const deleteEmployeeTerminal = (self, tiyData,id) => {
  tiyData.tParam.deleteEmployeeTerminalId = id;
  tiyData.tStatus.actionModal.isShow=true;
  tiyData.tStatus.actionModal.title="删除电脑标记";
};

export const webDeleteEmployeeTerminal = (self, tiyData) => {
  self.$Spin.show();
  self.$apiOther.deleteEmployeeTerminalMark({
    id:tiyData.tParam.deleteEmployeeTerminalId
  }).then(function (response) {
    self.$Spin.hide();
    if (response.success) {
      tiyData.tStatus.actionModal.isShow=false;
      webList(self, tiyData);
      self.$Message.success('提交成功!');
    } else {
      self.$Spin.hide();
      self.$Message.error(response.errorMessage);
    }
  });
};


